package com.ymatou.shop.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Gallery;

public class LowSpeedGallery extends Gallery {

	public LowSpeedGallery(Context context) {
		super(context);
	}
	
	public LowSpeedGallery(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	public LowSpeedGallery(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		float distance = e2.getX() - e1.getX();
		if(distance > 20){ //Check if scrolling left 
			onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, null);
			return true;
		}else if(distance < -20){//Otherwise scrolling right
		    onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
		    return true;
		}
	    return false;
	}
}
